package com.uenpay.im.ui.old.activity.personal;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.aswife.ui.MaskImageView;
import com.qyx.android.message.type.PacketType;
import com.uenpay.im.IMApplication;
import com.uenpay.im.R;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.weight.RoundImageView;
import com.uenpay.util.app.base.BaseActivity;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class QRCodeActivity extends BaseActivity {

    private MaskImageView imageView;
    private TextView user_name;
    private RoundImageView user_avatar;
    private String cust_id = "";
    private String cust_name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        isFullScreen = true;
        super.onCreate(savedInstanceState);
    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_qr_layout;
    }

    @Override
    public void initView(View view) {
        if (getIntent() != null && getIntent().hasExtra("cust_id")
                && getIntent().hasExtra("cust_name")) {
            cust_id = getIntent().getStringExtra("cust_id");
            cust_name = getIntent().getStringExtra("cust_name");
        }
        initView();
    }

    protected void initView() {
        imageView = (MaskImageView) findViewById(R.id.imageView);
        user_avatar = (RoundImageView) findViewById(R.id.user_avatar);
        user_name = (TextView) findViewById(R.id.user_name);
        String url = "";
        if (TextUtils.isEmpty(cust_id)) {
            ((TextView) findViewById(R.id.title_textview))
                    .setText(getResources().getString(R.string.my_qr_code));
            user_avatar.SetUrl(APIConfiguration.getAvatarUrlBig(IMApplication
                    .getCustId(), PacketType.PERSONAL));
            user_name.setText(IMApplication.config.getUserName());
            url = APIConfiguration.getBaseUrl() + "Cust/Cust/getCustQRCode?"
                    + APIConfiguration.getCustIdAndToken();
        } else {
            ((TextView) findViewById(R.id.title_textview))
                    .setText(getResources().getString(R.string.group_qr_code));
            user_avatar.SetUrl(APIConfiguration
                    .getAvatarUrlNormal(cust_id, PacketType.GROUP));
            user_name.setText(cust_name);
            url = APIConfiguration.getBaseUrl() + "Chat/Chat/getChatQRCode?chatid="
                    + cust_id + "&" + APIConfiguration.getCustIdAndToken();
        }
        imageView.SetUrl(url);

        //返回键
        findViewById(R.id.back_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                finish();
            }
        });

    }
}
